﻿namespace CRMG.Container.Source.OpManager
{
    using CRMG.Container.Resources.ExceptionResources;
    using CRMG.Container.Source.BO;
    using CRMG.Container.Source.DL;
    using CRMG.Container.Source.Variables;
    using Guru.ErrorHandling;
    using System;
    using System.Data;

    public class StudentManager
    {

        #region [ GetDetailsOfStudent method ]

        internal DataTable GetDetailsOfStudent(int studentId)
        {
            try
            {
                StudentDL stdntDL = new StudentDL();
                return stdntDL.GetDetailsOfStudent(studentId);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2099,
                    Title = Rc.GetString(2099)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ IsStudentExist method ]

        public bool IsStudentExist(string firstname, string lastname)
        {
            try
            {
                StudentDL stdntDL = new StudentDL();
                return stdntDL.IsStudentExist(firstname, lastname);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2076,
                    Title = Rc.GetString(2076)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ GetStudentList method ]

        public DataTable GetStudentList()
        {
            try
            {
                StudentDL stdntDL = new StudentDL();
                return stdntDL.GetStudentList();
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2076,
                    Title = Rc.GetString(2076)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ GetStudentById method ]

        public Student GetStudentById(int studentId)
        {
            try
            {
                StudentDL studentDL = new StudentDL();
                return studentDL.GetStudentById(studentId);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2075,
                    Title = Rc.GetString(2075)
                };
                throw new GuruException(exc, logger);
            }
        }
        #endregion


        #region [ AddStudent method ]

        public int AddStudent(Student stdnt)
        {
            try
            {
                StudentDL stdntDL = new StudentDL();
                return stdntDL.InsertAndGetId(stdnt);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2007,
                    Title = Rc.GetString(2007)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ GetActiveStudentList method ]

        public DataTable GetActiveStudentList()
        {
            try
            {
                StudentDL stdntDL = new StudentDL();
                return stdntDL.GetActiveStudentList();
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2010,
                    Title = Rc.GetString(2010)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ DeleteStudent method ]

        public void DeleteStudent(int studentId)
        {
            try
            {
                StudentDL stdntDL = new StudentDL();
                stdntDL.Update(new Student() { OBJID = studentId, IsActive = 0 });
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2078,
                    Title = Rc.GetString(2078)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ UpdateStudent method ]

        public void UpdateStudent(Student pStudent)
        {

            try
            {
                StudentDL stdntDL = new StudentDL();
                stdntDL.Update(pStudent);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2077,
                    Title = Rc.GetString(2077)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion
    }
}
